package com.amado.course50java8;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.function.Consumer;

/**
 * 相到于创建了三个consumer
 * @author wangyulong
 * @version 1.5.0
 * @date 2020/5/15 13:03
 */
public class ConsumerTest {
    public static void main(String[] args) {
        List<String> strings = Arrays.asList("a123", "b1234", "ab", "ab1245");
        List<String> list = new ArrayList<>();
        //创建一个consumer
        Consumer<String> consumer = (e)->{
            if(e.contains("a")){
                System.out.println("add:"+e);
                list.add(e);
            }
        };
        //andThen创建两个consumer
        consumer = consumer.andThen(e->{
            if(e.length()>4) {
                System.out.println("remove "+e);
                list.remove(e);
            }
        });
        //一共创建了三个consumer
        strings.forEach(consumer);
    }
}
